// pages/counter/counter.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 单价是price
    price:"",bottomlist:[2.6,'2.0',1.7,1.95,2.05,2.3,'3.0','4.0','取消'],ismask:false,
    // 木头尺寸索引2.6  2.0
    headerindex:0,area:0,sixarea:0,chengshu:'0%',total:0,allprice:0,
     list:[{diameter:'6cm',total:'',area:''},{diameter:'8cm',total:'',area:''},{diameter:'10cm',total:'',area:''},{diameter:'12cm',total:'',area:''},{diameter:'14cm',total:'',area:''},{diameter:'16cm',total:'',area:''},{diameter:'18cm',total:'',area:''},{diameter:'20cm',total:'',area:''},{diameter:'22cm',total:'',area:''},
     {diameter:'24cm',total:'',area:''},{diameter:'26cm',total:'',area:''},{diameter:'28cm',total:'',area:''},{diameter:'30cm',total:'',area:''}],
     twosix:[0.0111,0.018,0.026,0.037,0.049,0.063,0.079,0.097,0.116,0.137,0.160,0.185,0.211],
     two:[0.0079,0.013,0.019,0.027,0.036,0.047,0.059,0.072,0.086,0.102,0.120,0.138,0.185],
     oneseven:[0.0065,0.011,0.016,0.022,0.030,0.039,0.049,0.060,0.072,0.086,0.100,0.116,0.133],
     oneninefive:[0.0077,0.013,0.019,0.026,0.035,0.045,0.057,0.070,0.084,0.100,0.116,0.134,0.154],
     twozerotwo:[0.0080,0.013,0.020,0.027,0.037,0.047,0.059,0.073,0.087,0.103,0.121,0.140,0.160],
     twothree:[0.0095,0.015,0.023,0.032,0.042,0.055,0.069,0.084,0.101,0.120,0.140,0.161,0.185],
     three:[0.0134,0.021,0.031,0.043,0.058,0.075,0.093,0.114,0.137,0.161,0.188,0.217,0.248],
     four:[0.0201,0.031,0.045,0.062,0.083,0.106,0.132,0.160,0.191,0.225,0.262,0.302,0.344]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  showmodel(){
    this.setData({
      ismask:true
    })
  },
  getval(e){
    console.log(e);
    let value=e.detail.value
    let index=e.currentTarget.dataset.index
    let list=this.data.list
  //  这个twosix其实是公共变量  不是twosix这个数组
    let arr=[]
   
    if(this.data.headerindex==0){
      arr=this.data.twosix
    }
    if(this.data.headerindex==1){
      arr=this.data.two
    }
    if(this.data.headerindex==2){
      arr=this.data.oneseven
    }
    if(this.data.headerindex==3){
      arr=this.data.oneninefive
    }
    if(this.data.headerindex==4){
      arr=this.data.twozerotwo
    }
    if(this.data.headerindex==5){
      arr=this.data.twothree
    }
    if(this.data.headerindex==6){
      arr=this.data.three
    }
    if(this.data.headerindex==7){
      arr=this.data.four
    }
    list[index].area=(arr[index]*value).toFixed(4)
    list[index].total=e.detail.value
    this.setData({
      list
    })
    // 总条数
    let total=0
    let area=0
    // 6cnm的方数
    let sixarea=0
    // 大于10cm的方数
    let bigtenarea=0
    let allprice=0
    list.forEach((item,index)=>{
     total+=+item.total
     area+=+item.area
     if(index==0){
       sixarea=+item.area
     }
     if(index>=2){
     bigtenarea+=+item.area
     }
      
    })
// sixarea是为了计算总价   为了让getprice方法里用到这个数据
    this.setData({
      sixarea,
      
      total,
      area:area.toFixed(4),
       chengshu:(bigtenarea/area*100).toFixed(4)+'%',
       
    })
    if(this.data.price){
this.setData({
  allprice:area*this.data.price-sixarea*100
})
    }
    
     
    
   
  },
  getprice(e){
    if(e.detail.value){
      this.setData({
        price:e.detail.value,
        allprice:this.data.area*e.detail.value-this.data.sixarea*100
      })
    }else{
      this.setData({
        allprice:0
      })
    }
      
  },
  getnumber(e){
    let index=e.currentTarget.dataset.index
    if(index!=this.data.headerindex&&index!=this.data.bottomlist.length-1){
      this.clear()
    }
     if(index==this.data.bottomlist.length-1){
      //  点击的是取消
      this.setData({
        ismask:false
      })
     }else{
       this.setData({
         ismask:false,
         headerindex:index
       })
     }

  },
  clear(){
    let list=this.data.list
    list.forEach((item,index)=>{
     item.total=''
     item.area=''
       
     })
    this.setData({
      area:0,
      sixarea:0,
      price:0,
      list,
      allprice:0,
      chengshu:0,
      total:0,
      headerindex:0
    })
  }
})